package com.ruangong.GitClient.GitHubAPI;

import okhttp3.OkHttpClient;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
import java.io.IOException;

public class NetworkUtils {

    public static final String CLIENT_ID = "Iv1.66524b24eade259a";
    public static final String CLIENT_SECRET = "e316193849a26351b48f97fb49dcc958e29f93c4";
    public static final String SCOPES = "repo,admin:org,admin:public_key,admin:repo_hook,admin:org_hook,gist,notifications,user,delete_repo,write:discussion";
    public static final String REDIRECT_URI = "myapp://oauth";

    public static void fetchAccessToken(String code, Callback callback) {
        OkHttpClient client = new OkHttpClient();
        RequestBody body = new FormBody.Builder()
                .add("client_id", CLIENT_ID)
                .add("client_secret", CLIENT_SECRET)
                .add("code", code)
                .add("redirect_uri", REDIRECT_URI)
                .build();

        Request request = new Request.Builder()
                .url("https://github.com/login/oauth/access_token")
                .post(body)
                .build();

        client.newCall(request).enqueue(callback);
    }
}

